package com.titanrise.crm.common.utils;

import java.util.function.Supplier;
import java.util.function.Function;

public class SupplierPipeUtil {
    public static <A> Supplier<A> of(A a) {
        return () -> a;
    }

    public static <A, B> Function<Supplier<A>, Supplier<B>> map(Function<A, B> fn) {
        return (supplierA) -> () -> fn.apply(supplierA.get());
    }

    public static <A, B> Function<Supplier<A>, Supplier<B>> flatMap(Function<A, Supplier<B>> fn) {
        return (supplierA) -> fn.apply(supplierA.get());
    }

    public static <A, B> Function<Supplier<A>, Supplier<B>> andThen(Supplier<B> supplierB) {
        return (supplierA) -> () -> {
            supplierA.get();
            return supplierB.get();
        };
    }

    public static Supplier<Nothing> emptySupplier = () -> Nothing.value;
}
